package entity;

import java.util.List;
import java.util.logging.Level;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * Facade for entity ManterAnamnese.
 * 
 * @see entity.ManterAnamnese
 * @author MyEclipse Persistence Tools
 */
@Stateless
public class ManterAnamneseFacade implements ManterAnamneseFacadeLocal,
		ManterAnamneseFacadeRemote {
	// property constants
	public static final String IS_TRATAMENTO_MEDICO = "isTratamentoMedico";
	public static final String TRATAMENTO = "tratamento";
	public static final String IS_TOMANDO_MEDICAMENTO = "isTomandoMedicamento";
	public static final String MEDICAMENTO = "medicamento";
	public static final String NOME_MEDICO = "nomeMedico";
	public static final String DIABETES = "diabetes";
	public static final String SIFILIS = "sifilis";
	public static final String CARDIOPATIAS = "cardiopatias";
	public static final String EPLEPSIA = "eplepsia";
	public static final String FEBRE_REUMATICA = "febreReumatica";
	public static final String PRESSAO_ALTA = "pressaoAlta";
	public static final String PRESSAO_BAIXA = "pressaoBaixa";
	public static final String DORES_NO_PEITO = "doresNoPeito";
	public static final String DORES_NAS_COSTAS = "doresNasCostas";
	public static final String FALTA_DE_AR = "faltaDeAr";
	public static final String TIPO_TRAVESSEIRO = "tipoTravesseiro";
	public static final String TONTURAS = "tonturas";
	public static final String DESMAIOS = "desmaios";
	public static final String ANESTESIA_LOCAL = "anestesiaLocal";
	public static final String ANESTESIA_GERAL = "anestesiaGeral";
	public static final String PROBLEMAS_ANESTESIA = "problemasAnestesia";
	public static final String EXTRAIU_DENTE = "extraiuDente";
	public static final String ACIDENTE_EXTRACAO = "acidenteExtracao";
	public static final String ALERGIA_MEDICAMENTO = "alergiaMedicamento";
	public static final String QUE_MEDICAMENTO = "queMedicamento";
	public static final String IS_GRAVIDA = "isGravida";
	public static final String DIFICULDADE_RESPIRACAO = "dificuldadeRespiracao";
	public static final String INCHACO_PERNAS = "inchacoPernas";

	@PersistenceContext
	private EntityManager entityManager;

	/**
	 * Perform an initial save of a previously unsaved ManterAnamnese entity.
	 * All subsequent persist actions of this entity should use the #update()
	 * method.
	 * 
	 * @param entity
	 *            ManterAnamnese entity to persist
	 * @throws RuntimeException
	 *             when the operation fails
	 */
	public void save(ManterAnamnese entity) {
		LogUtil.log("saving ManterAnamnese instance", Level.INFO, null);
		try {
			entityManager.persist(entity);
			LogUtil.log("save successful", Level.INFO, null);
		} catch (RuntimeException re) {
			LogUtil.log("save failed", Level.SEVERE, re);
			throw re;
		}
	}

	/**
	 * Delete a persistent ManterAnamnese entity.
	 * 
	 * @param entity
	 *            ManterAnamnese entity to delete
	 * @throws RuntimeException
	 *             when the operation fails
	 */
	public void delete(ManterAnamnese entity) {
		LogUtil.log("deleting ManterAnamnese instance", Level.INFO, null);
		try {
			entity = entityManager.getReference(ManterAnamnese.class, entity
					.getNumeroProntuario());
			entityManager.remove(entity);
			LogUtil.log("delete successful", Level.INFO, null);
		} catch (RuntimeException re) {
			LogUtil.log("delete failed", Level.SEVERE, re);
			throw re;
		}
	}

	/**
	 * Persist a previously saved ManterAnamnese entity and return it or a copy
	 * of it to the sender. A copy of the ManterAnamnese entity parameter is
	 * returned when the JPA persistence mechanism has not previously been
	 * tracking the updated entity.
	 * 
	 * @param entity
	 *            ManterAnamnese entity to update
	 * @return ManterAnamnese the persisted ManterAnamnese entity instance, may
	 *         not be the same
	 * @throws RuntimeException
	 *             if the operation fails
	 */
	public ManterAnamnese update(ManterAnamnese entity) {
		LogUtil.log("updating ManterAnamnese instance", Level.INFO, null);
		try {
			ManterAnamnese result = entityManager.merge(entity);
			LogUtil.log("update successful", Level.INFO, null);
			return result;
		} catch (RuntimeException re) {
			LogUtil.log("update failed", Level.SEVERE, re);
			throw re;
		}
	}

	public ManterAnamnese findById(Integer id) {
		LogUtil.log("finding ManterAnamnese instance with id: " + id,
				Level.INFO, null);
		try {
			ManterAnamnese instance = entityManager.find(ManterAnamnese.class,
					id);
			return instance;
		} catch (RuntimeException re) {
			LogUtil.log("find failed", Level.SEVERE, re);
			throw re;
		}
	}

	/**
	 * Find all ManterAnamnese entities with a specific property value.
	 * 
	 * @param propertyName
	 *            the name of the ManterAnamnese property to query
	 * @param value
	 *            the property value to match
	 * @param rowStartIdxAndCount
	 *            Optional int varargs. rowStartIdxAndCount[0] specifies the the
	 *            row index in the query result-set to begin collecting the
	 *            results. rowStartIdxAndCount[1] specifies the the maximum
	 *            number of results to return.
	 * @return List<ManterAnamnese> found by query
	 */
	@SuppressWarnings("unchecked")
	public List<ManterAnamnese> findByProperty(String propertyName,
			final Object value, final int... rowStartIdxAndCount) {
		LogUtil.log("finding ManterAnamnese instance with property: "
				+ propertyName + ", value: " + value, Level.INFO, null);
		try {
			final String queryString = "select model from ManterAnamnese model where model."
					+ propertyName + "= :propertyValue";
			Query query = entityManager.createQuery(queryString);
			query.setParameter("propertyValue", value);
			if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) {
				int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
				if (rowStartIdx > 0) {
					query.setFirstResult(rowStartIdx);
				}

				if (rowStartIdxAndCount.length > 1) {
					int rowCount = Math.max(0, rowStartIdxAndCount[1]);
					if (rowCount > 0) {
						query.setMaxResults(rowCount);
					}
				}
			}
			return query.getResultList();
		} catch (RuntimeException re) {
			LogUtil.log("find by property name failed", Level.SEVERE, re);
			throw re;
		}
	}

	public List<ManterAnamnese> findByIsTratamentoMedico(
			Object isTratamentoMedico, int... rowStartIdxAndCount) {
		return findByProperty(IS_TRATAMENTO_MEDICO, isTratamentoMedico,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByTratamento(Object tratamento,
			int... rowStartIdxAndCount) {
		return findByProperty(TRATAMENTO, tratamento, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByIsTomandoMedicamento(
			Object isTomandoMedicamento, int... rowStartIdxAndCount) {
		return findByProperty(IS_TOMANDO_MEDICAMENTO, isTomandoMedicamento,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByMedicamento(Object medicamento,
			int... rowStartIdxAndCount) {
		return findByProperty(MEDICAMENTO, medicamento, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByNomeMedico(Object nomeMedico,
			int... rowStartIdxAndCount) {
		return findByProperty(NOME_MEDICO, nomeMedico, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByDiabetes(Object diabetes,
			int... rowStartIdxAndCount) {
		return findByProperty(DIABETES, diabetes, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findBySifilis(Object sifilis,
			int... rowStartIdxAndCount) {
		return findByProperty(SIFILIS, sifilis, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByCardiopatias(Object cardiopatias,
			int... rowStartIdxAndCount) {
		return findByProperty(CARDIOPATIAS, cardiopatias, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByEplepsia(Object eplepsia,
			int... rowStartIdxAndCount) {
		return findByProperty(EPLEPSIA, eplepsia, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByFebreReumatica(Object febreReumatica,
			int... rowStartIdxAndCount) {
		return findByProperty(FEBRE_REUMATICA, febreReumatica,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByPressaoAlta(Object pressaoAlta,
			int... rowStartIdxAndCount) {
		return findByProperty(PRESSAO_ALTA, pressaoAlta, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByPressaoBaixa(Object pressaoBaixa,
			int... rowStartIdxAndCount) {
		return findByProperty(PRESSAO_BAIXA, pressaoBaixa, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByDoresNoPeito(Object doresNoPeito,
			int... rowStartIdxAndCount) {
		return findByProperty(DORES_NO_PEITO, doresNoPeito, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByDoresNasCostas(Object doresNasCostas,
			int... rowStartIdxAndCount) {
		return findByProperty(DORES_NAS_COSTAS, doresNasCostas,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByFaltaDeAr(Object faltaDeAr,
			int... rowStartIdxAndCount) {
		return findByProperty(FALTA_DE_AR, faltaDeAr, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByTipoTravesseiro(Object tipoTravesseiro,
			int... rowStartIdxAndCount) {
		return findByProperty(TIPO_TRAVESSEIRO, tipoTravesseiro,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByTonturas(Object tonturas,
			int... rowStartIdxAndCount) {
		return findByProperty(TONTURAS, tonturas, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByDesmaios(Object desmaios,
			int... rowStartIdxAndCount) {
		return findByProperty(DESMAIOS, desmaios, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByAnestesiaLocal(Object anestesiaLocal,
			int... rowStartIdxAndCount) {
		return findByProperty(ANESTESIA_LOCAL, anestesiaLocal,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByAnestesiaGeral(Object anestesiaGeral,
			int... rowStartIdxAndCount) {
		return findByProperty(ANESTESIA_GERAL, anestesiaGeral,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByProblemasAnestesia(
			Object problemasAnestesia, int... rowStartIdxAndCount) {
		return findByProperty(PROBLEMAS_ANESTESIA, problemasAnestesia,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByExtraiuDente(Object extraiuDente,
			int... rowStartIdxAndCount) {
		return findByProperty(EXTRAIU_DENTE, extraiuDente, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByAcidenteExtracao(Object acidenteExtracao,
			int... rowStartIdxAndCount) {
		return findByProperty(ACIDENTE_EXTRACAO, acidenteExtracao,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByAlergiaMedicamento(
			Object alergiaMedicamento, int... rowStartIdxAndCount) {
		return findByProperty(ALERGIA_MEDICAMENTO, alergiaMedicamento,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByQueMedicamento(Object queMedicamento,
			int... rowStartIdxAndCount) {
		return findByProperty(QUE_MEDICAMENTO, queMedicamento,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByIsGravida(Object isGravida,
			int... rowStartIdxAndCount) {
		return findByProperty(IS_GRAVIDA, isGravida, rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByDificuldadeRespiracao(
			Object dificuldadeRespiracao, int... rowStartIdxAndCount) {
		return findByProperty(DIFICULDADE_RESPIRACAO, dificuldadeRespiracao,
				rowStartIdxAndCount);
	}

	public List<ManterAnamnese> findByInchacoPernas(Object inchacoPernas,
			int... rowStartIdxAndCount) {
		return findByProperty(INCHACO_PERNAS, inchacoPernas,
				rowStartIdxAndCount);
	}

	/**
	 * Find all ManterAnamnese entities.
	 * 
	 * @param rowStartIdxAndCount
	 *            Optional int varargs. rowStartIdxAndCount[0] specifies the the
	 *            row index in the query result-set to begin collecting the
	 *            results. rowStartIdxAndCount[1] specifies the the maximum
	 *            count of results to return.
	 * @return List<ManterAnamnese> all ManterAnamnese entities
	 */
	@SuppressWarnings("unchecked")
	public List<ManterAnamnese> findAll(final int... rowStartIdxAndCount) {
		LogUtil.log("finding all ManterAnamnese instances", Level.INFO, null);
		try {
			final String queryString = "select model from ManterAnamnese model";
			Query query = entityManager.createQuery(queryString);
			if (rowStartIdxAndCount != null && rowStartIdxAndCount.length > 0) {
				int rowStartIdx = Math.max(0, rowStartIdxAndCount[0]);
				if (rowStartIdx > 0) {
					query.setFirstResult(rowStartIdx);
				}

				if (rowStartIdxAndCount.length > 1) {
					int rowCount = Math.max(0, rowStartIdxAndCount[1]);
					if (rowCount > 0) {
						query.setMaxResults(rowCount);
					}
				}
			}
			return query.getResultList();
		} catch (RuntimeException re) {
			LogUtil.log("find all failed", Level.SEVERE, re);
			throw re;
		}
	}

}